package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbDeviceAttr;
import com.group.service.DeviceAttrService;

/**
 * 设备属性服务
 * 
 * @author YSH
 *
 */
@Controller
@RequestMapping("/deviceAttr")
public class DeviceAttrController {
	@Autowired
	private DeviceAttrService deviceAttrService;

	@RequestMapping("/page.action")
	public String deviceAttrPath() {
		return "info/device/deviceAttr";
	}
	
	@RequestMapping("/query.action")
	@ResponseBody
	public List<TbDeviceAttr> query(TbDeviceAttr deviceAttr) {
		List<TbDeviceAttr> list = deviceAttrService.query(deviceAttr);
		return list;
	}
	
	@RequestMapping("/update.action")
	@ResponseBody
	public Map<String, String> update(TbDeviceAttr deviceAttr) {
		Map<String, String> map =  deviceAttrService.update(deviceAttr);
		return map;
	}

	@RequestMapping("/getAllDeviceAttrInfo.action")
	@ResponseBody
	public List<TbDeviceAttr> getAllDeviceAttrInfo() {
		return deviceAttrService.getAllDeviceAttrInfo();
	}

	// 根据设备名称获得设备属性名称
	@RequestMapping("/getAllDeviceAttrByName.action")
	@ResponseBody
	public List<TbDeviceAttr> getAllDeviceAttrByName(String deviceName) {

		return deviceAttrService.getAllDeviceAttrByName(deviceName);
	}

	// 添加新的设备属性信息
	@RequestMapping("/saveNewDeviceAttr.action")
	@ResponseBody
	public String saveNewDeviceAttr(TbDeviceAttr deviceAttr, HttpServletRequest request) {
		String str = deviceAttrService.saveNewDeviceAttr(deviceAttr, request);
		return str;
	}

	// 通过id查询设备属性信息
	@RequestMapping("/getDeviceAttrById.action")
	@ResponseBody
	public List<TbDeviceAttr> getDeviceAttrById(String Id) {
		return deviceAttrService.getDeviceAttrById(Id);
	}

	// 修改设备的属性
	@RequestMapping("/updateDeviceAttr.action")
	@ResponseBody
	public Map<String, String> updateDeviceAttr(TbDeviceAttr deviceAttr) {
		return deviceAttrService.updateDeviceAttr(deviceAttr);
	}

	@RequestMapping("/deleteDeviceAttrInfo.action")
	@ResponseBody
	public Map<String, String> deleteDeviceAttrInfo(@RequestParam(value = "deviceAttrIds[]") String[] deviceAttrIds) {
		Map<String, String> map = deviceAttrService.deleteDeviceAttrInfo(deviceAttrIds);
		return map;
	}

	// 添加设备属性时的属性验证
	@RequestMapping("/addDeviceCheckattrName.action")
	@ResponseBody
	public String addDeviceCheckattrName(String attrName, String deviceId) {
		String success = deviceAttrService.addDeviceCheckattrName(attrName, deviceId);
		return success;
	}

	// 修改设备属性时的属性验证
	@RequestMapping("/updateDeviceCheckattrName.action")
	@ResponseBody
	public String updateDeviceCheckattrName(String attrName, String deviceId, String id) {
		String success = deviceAttrService.updateDeviceCheckattrName(attrName, deviceId, id);
		return success;
	}
}
